package com.nuoniu.sibanyun.controller.finance;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.VRuleVoucherType;
import com.nuoniu.sibanyun.service.finance.IVRuleVoucherTypeService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 凭证分类 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2022-06-13
 */
@RestController
@RequestMapping("voucherType")
@Api(tags = "凭证分类管理")
public class VRuleVoucherTypeController extends BaseController {

    @Autowired
    private IVRuleVoucherTypeService typeService;

    @ApiOperation("获取凭证分类列表")
    @GetMapping("getList")
    public HttpResult getList(Integer type) {
        return HttpResult.ok(typeService.getList(type));
    }

    @ApiOperation("保存分类")
    @PostMapping("save")
    public HttpResult save(@RequestBody VRuleVoucherType type) {
        if(type == null || StringUtils.isBlank(type.getName())) {
            return HttpResult.error("名称不能为空");
        }

        typeService.saveType(type);
        return HttpResult.ok();
    }

    @ApiOperation("删除分类")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        typeService.delete(id);
        return HttpResult.ok();
    }
}
